from manim import *
class CustomCurve(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [17,25,0],
            [12,20,0],
            [17,15,0]
            
        ]
        self.set_points_smoothly(points)

class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(60*2+1):       
            dot1=Dot([-500,5*(i-60),0]).set_opacity(0.5)
            dot2=Dot([500,5*(i-60),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(100*2+1):        
            dot3=Dot([(i-100)*5,-300,0]).set_opacity(0.5)
            dot4=Dot([(i-100)*5,300,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        
        #镜头跟进效果 
        self.camera.frame.save_state()

        

        text43 = Tex(
                    r"$L_{x}=0$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-20,6,0])
        text44 = Tex(
                    r"$L_{y}=0$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-20,0,0])
        text45 = Tex(
                    r"$L_{z}=0$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-20,-6,0])
        text46 = Tex(
                    r"$L_{\lambda }=0$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-20,-12,0])
        self.play(Create(text43),Create(text44),Create(text45),Create(text46))
        rectangle7=Rectangle(color=BLUE,fill_opacity=0.0,width=10,height=16
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle7.move_to([-20,0,0])
        self.play(Create(rectangle7))
        text47 = Tex(
                    r"\text{含参方程}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle7,UP,buff=1)
        self.play(Create(text47))
        rectangle8=Rectangle(color=BLUE,fill_opacity=0.0,width=10,height=5
                            ,stroke_color=PURPLE,stroke_width=20)
        rectangle8.move_to([-20,-12,0])
        self.play(Create(rectangle8))
        text48 = Tex(
                    r"\text{无参方程}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle8,DOWN,buff=1)
        self.play(Create(text48))
        #箭头引出
        arrow5 = Arrow(start=[-10,0,0],end=[0,0,0], color=GREEN
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow5))
        text49 = Tex(
                    r"\text{消参}",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,3,0])
        text50 = Tex(
                    r"\text{得无参方程}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([8,0,0])
        text51 = Tex(
                    r"\text{(取决于需要)}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text50,RIGHT,buff=1)
        self.play(Create(text49),Create(text50))
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
        self.play(Create(text51))

        #箭头引出
        arrow6 = Arrow(start=[-13,-17,0],end=[10,-17,0], color=BLUE
                       , stroke_width=20, tip_length=1)
        arrow7 = Arrow(start=[6,-3,0],end=[15,-14,0], color=BLUE
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow6),Create(arrow7))

        text52 = Tex(
                    r"\text{联立得驻点}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-17,0])
        self.play(Create(text52))

        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=6,height=4
                            ,stroke_color=PURPLE,stroke_width=20)
        rectangle.move_to([-5,3,0])
        self.play(Create(rectangle))

        arrow8 = Arrow(start=[-5,5,0],end=[0,20,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow8))
        text53 = Tex(
                    r"\text{三种思路}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([6,20,0])
        self.play(Create(text53))
        curve = CustomCurve(color=WHITE, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve))
        text54 = Tex(
                    r"\text{除}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([25,25,0])
        
        text540 = Tex(
                    r"\text{(方程简单)}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text54,RIGHT,buff=1)
        
        text55 = Tex(
                    r"\text{减}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([25,20,0])
        
        text550 = Tex(
                    r"\text{(有轮换对称性)}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text55,RIGHT,buff=1)
        text56 = Tex(
                    r"\text{行列式}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([25,15,0])
        text560 = Tex(
                    r"\text{(二元一次方程)}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text56,RIGHT,buff=1)
        self.play(Create(text56),Create(text54),Create(text55))


        self.play(Create(text540))
        self.play(Create(text550)) 
        self.play(Create(text560))
        self.wait()

       